package com.org.shichui.controller;

import com.org.shichui.model.BaseResponse;
import com.org.shichui.pojo.User;
import com.org.shichui.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/userLogin")
public class LoginController {

    @Resource
    private UserService userService;

    @RequestMapping("/toLogin")
    public BaseResponse<User> login(String phone,String password){
        User login = userService.login(phone, password);
        if(login!=null){
            if(0==login.getStatus()){
                return new BaseResponse<User>(100,"登陆失败 套餐已到期，请找管理员续费",null);
            }
            return new BaseResponse<User>(200,"登录成功",login);
        }
        return new BaseResponse<User>(100,"用户名或者密码不正确",null);
    }

    @RequestMapping("/toReg")
    public BaseResponse<User> regAdmin(User user){
        BaseResponse<User> login = userService.register(user);
        return login;
    }

}
